package com.xiangyi.teachingsystem.admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xiangyi.teachingsystem.entity.po.CourseRes;
import com.xiangyi.teachingsystem.entity.po.GroupRes;
import com.xiangyi.teachingsystem.entity.po.PrivateRes;
import com.xiangyi.teachingsystem.entity.vo.Result;
import com.xiangyi.teachingsystem.service.CourseResService;
import com.xiangyi.teachingsystem.service.GroupResService;
import com.xiangyi.teachingsystem.service.GroupReviewService;
import com.xiangyi.teachingsystem.service.PrivateResService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/resOper")
public class AdminResController {
    @Autowired
    PrivateResService privateResService;

    @GetMapping("/delPubRes")
    public Result delPubRes(@RequestParam Integer resId){
        privateResService.remove(new QueryWrapper<PrivateRes>()
                .eq("public_sign",true)
                .eq("id",resId));
        return Result.success("资源移除成功");
    }

    @PostMapping("/addPubRes")
    public Result addPubRes(@RequestBody PrivateRes privateRes){
        try {
            privateRes.setPublicSign(true);
            privateResService.save(privateRes);
            return Result.success("资源上传成功");
        }catch (Exception e){
            e.printStackTrace();
            return Result.failure("服务器错误").setData(e.getMessage());
        }
    }



    @GetMapping("/priResList")
    public Result priResList(){
        List<PrivateRes> privateResList = privateResService.getBaseMapper()
                .selectList(null);
        return Result.success("私有资源列表查询成功").setData(privateResList);
    }

    @GetMapping("/delPriRes")
    public Result delPriRes(@RequestParam Integer resId){
        privateResService.remove(new QueryWrapper<PrivateRes>()
                .eq("public_sign",false)
                .eq("id",resId));
        return Result.success("资源移除成功");
    }



    @Autowired
    CourseResService courseResService;

    @GetMapping("/courseResList")
    public Result courseResList(){
        List<CourseRes> courseRes = courseResService.courseResList();
        return Result.success("课程资源列表查询成功").setData(courseRes);
    }

    @GetMapping("/delCourseRes")
    public Result delCourseRes(@RequestParam Integer resId){
        courseResService.removeById(resId);
        return Result.success("课程资源移除成功");
    }

    @Autowired
    GroupResService groupResService;

    @GetMapping("/groupResList")
    public Result groupResList(){
        List<GroupRes>  groupRes= groupResService.groupResList();
        return Result.success("小组资源列表查询成功").setData(groupRes);
    }

    @GetMapping("/delGroupRes")
    public Result delGroupRes(@RequestParam Integer resId){
        groupResService.removeById(resId);
        return Result.success("小组资源移除成功");
    }


}
